-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run tests with pytest #963
Conversation
92dd2fb
to
2537360
Compare
So, basically, please clone this and have a look at it, just be prepared to force-reset your local copy when I update it 😄 |
4a4a190
to
4d7963e
Compare
cae613f
to
1c9b78e
Compare
50d0e31
to
bc96bde
Compare
Pytest truncates expressions from failed asserts, which is a bit counterproductive in CI
🎉 rebased it to squash some of the obviously-related commits together, but I'm mostly happy with the history and don't want to spend ages re-ordering it. @rouault merge when you're happy 😄 |
... unless you think the commit history needs improving in which case I can spend a little longer on it of course. |
No, that'll be fine like that. This will reflect well the effort you put in this :-) |
frustrating OSX CI error; no changes since previous successful build 🤦♂️ |
At @schwehr's suggestion I did a quick performance comparison on my vagrant box: master: pytestify: So basically this adds 87s on to test runs. I suppose some performance drop is inevitable but I'm a bit surprised it's as large as that. |
In the meantime, the OSX CI error went away with a rebuild 👍 ; maybe that one's unrelated to this effort |
I don't think the increased test time is a problem particularly. I'd prefer to just mitigate it by disabling a few of the slower tests by default: (output from
I won't do that here because it just makes the comparison less fair, but happy to do it as a followup PR. |
@craigds I've rebased my gdalbarn branch on top of master with the pytest changes, and I now get a "The job exceeded the maximum log length, and has been terminated." on the trusty_clang config : https://travis-ci.org/rouault/gdal/jobs/466516798 . This is apparently really related to the log length, and not the time out |
Yeah, I think maybe we take away the |
At the same time, if we don't print anything for too long, Travis will kill us because of this. I'm not clear why the pytest output doesn't please Travis. Perhaps each line is just slightly longer than before, but the number of lines should be similar. |
Using -ra did the job. |
@rouault One less drastic thing we could do is add |
I gave a talk about this effort yesterday at Pycon AU. Description: https://2019.pycon-au.org/talks/how-i-migrated-a-huge-oss-project-to-use-pytest |
Thanks for the link, and thanks again for the incredible job you did ! I enjoy so much being able to write tests in a more compact way. |
What does this PR do?
https://trac.osgeo.org/gdal/wiki/rfc72_pytest
The intent is to use pytest to run the GDAL test suite.
Large parts of this PR are automated, but manual pieces are in their own separate commits for reviewability. The automated commits are probably too large to review on github.
Notable changes and their implications
cd autotest ; pytest
. (The first time you may need topip install -r requirements.txt
to install pytest)test_<name>
. Pytest finds tests by matching names against a regex (this is the default regex).test_py_scripts.run_py_script
was modified to always run the script as a subprocess. The stdout capturing of the original method did strange things with pytest. This change broke some tests that relied on passing files in the/vsimem/
root to scripts, so I've changed those to use thetmp/
root instead.Changes not included in this PR
gdaltest.<drivername>_drv
variables and replaced them with pytest fixtures. That's probably related to making functions independent, and is also future work.What are related issues/pull requests?
Tasklist
Get test collection working
Manually parametrize the 50-ish remaining dynamically-generated tests (e.g.
gdaltest_list.append((ut.testProj, item[6]))
)Automated conversion
test_*
compatibility shim for old tests- Instead, I'm aiming to replace allreturn 'skip' / 'fail'
. It's nearly therepost_reason
/return 'fail'
calls where possible../pymod
entries from sys.path, now that they're all running in one process__main__
block andgdaltest_list
from test filesManually review remaining
gdaltest_list.append(...)
cases and addpytest.skip()
as appropriate. Possibly automate some of this somehow?Clean up remaining fails manually. Remaining failures checklist
Ensure the slow/internet tests are still marked as such and skipped by default. (note: check autotest: update environment variable requirements #1054)
Add documentation:
Consider adding extra niceties to make sure people still like me after this huge PR
--color=no
to avoid ansi control chars in travis' raw logs)Review
Adjust for comments
All CI builds and checks have passed